package com.liang.codegenerate;


import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.annotation.Resource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

@SpringBootTest
public class testJdbc {


    @Test
    public void main() throws SQLException {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/code");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");
        Connection connection = null;
        try {
            connection = dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("连接失败");
        }
        if (connection == null){
            System.out.println("连接失败null");
        }

        System.out.println("连接成功");
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        List<Object> databases = Collections.singletonList(jdbcTemplate.queryForList("DESC user"));
        System.out.println(databases.toString());
    }

}
